package com.fan.configserver.service;

import com.fan.configserver.exception.QhException;
import com.fan.configserver.exception.QhUserErrors;
import com.fan.configserver.mapper.UserMapper;
import com.fan.configserver.po.User;
import com.fan.configserver.po.UserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * java类简单作用描述
 *
 * @Description: java类作用描述
 * @Author: hf
 * @CreateDate: 2018/9/27 11:30
 * @UpdateUser: hf
 * @UpdateDate: 2018/9/27 11:30
 * @UpdateRemark: The modified content
 * @Version: 1.0
 */
@Service
public class UserService {
    @Autowired
    UserMapper userMapper;

    public User getUserById(Long userId) {
        return userMapper.selectByPrimaryKey(userId);
    }

    public User getUserByUserName(String userName) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        criteria.andUserNameEqualTo(userName);
        List<User> userList = userMapper.selectByExample(userExample);
        if (userList.isEmpty()) {
            throw new QhException(QhUserErrors.USER_IS_NULL);
        }
        return userList.get(0);
    }
}
